package logic

import (
	"context"

	"rent-ease/models"

	"rent-ease/userrpc/internal/svc"
	"rent-ease/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *userrpc.ListRequest) (*userrpc.ListResponse, error) {
	// todo: add your logic here and delete this line
	var houses []models.House
	models.DB.Find(&houses)
	var houselist []*userrpc.HouseList
	for _, house := range houses {
		list := &userrpc.HouseList{
			Id:    int64(house.ID),
			Name:  house.Name,
			Price: float32(house.Price),
			Num:   int64(house.Num),
		}
		houselist = append(houselist, list)
	}
	return &userrpc.ListResponse{
		List: houselist,
	}, nil
}
